package org.aphasia4j.service.impl;

import java.util.List;

import org.aphasia4j.dao.TaskDao;
import org.aphasia4j.dao.WordDao;
import org.aphasia4j.model.Task;
import org.aphasia4j.model.Word;
import org.aphasia4j.model.WordPractice;
import org.aphasia4j.service.TaskService;

/**
 * Implementation of the {@link TaskService} interface description.
 * 
 * @author hillger.t
 */
public class TaskServiceImpl extends BaseServiceImpl<TaskDao, Task> implements TaskService {
  private WordDao wordDao;

  public void setWordDao(WordDao wordDao) {
    this.wordDao = wordDao;
  }

  @Override
  public Task newPicturePracticeTask(int wordCount) {
    return newPicturePracticeTask(wordCount, 1);
  }

  @Override
  public Task newPicturePracticeTask(int wordCount, int practiceCount) {
    Task task = new Task();

    for (int i = 1; i <= practiceCount; i++) {
      List<Word> words = wordDao.getWords(wordCount);

      WordPractice practice = new WordPractice();
      practice.setName("Word practice #" + i);
      practice.setWords(words);
      practice.setWord(words.get(0)); // TODO: select a word randomly.
      task.addPractice(practice);
    }

    return task;
  }

  @Override
  public List<Task> findTasksByPatient(long patientId) {
    return this.dao.findByPatient(patientId);
  }

  @Override
  public List<Task> findTasksByPatientName(String name) {
    return this.dao.findByPatientName(name);
  }
}
